/*
 * @Description:
 * @Version: 2.0
 * @Date: 2024-04-09 11:38:56
 * @LastEditTime: 2024-06-05 16:56:47
 */
import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import path from "path";
// 引入elementplus插件
import AutoImport from "unplugin-auto-import/vite";
import Components from "unplugin-vue-components/vite";
import { ElementPlusResolver } from "unplugin-vue-components/resolvers";
import legacy from "@vitejs/plugin-legacy";

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    AutoImport({
      resolvers: [ElementPlusResolver()],
    }),
    Components({
      resolvers: [ElementPlusResolver()],
    }),
    legacy({
      // targets: ['Chrome 64'],
      modernPolyfills: true,
      targets: ["defaults", "ie >= 11", "chrome 52", "android <= 8"], //需要兼容的目标列表，可以设置多个
      additionalLegacyPolyfills: ["regenerator-runtime/runtime"],
      renderLegacyChunks: true,
      polyfills: [
        "es.symbol",
        "es.array.filter",
        "es.promise",
        "es.promise.finally",
        "es/map",
        "es/set",
        "es.array.for-each",
        "es.object.define-properties",
        "es.object.define-property",
        "es.object.get-own-property-descriptor",
        "es.object.get-own-property-descriptors",
        "es.object.keys",
        "es.object.to-string",
        "web.dom-collections.for-each",
        "esnext.global-this",
        "esnext.string.match-all",
      ],
    }),
  ],
  // 配置文件引用别名 alias
  resolve: {
    alias: {
      '@': path.resolve(__dirname, 'src')
    },
  },
  //  代理服务器配置
  server: {
    open: true, //自动打开浏览器
    hmr: true, //热更新，保存自动刷新
    host: "0.0.0.0",
    port: 5173, //运行端口
    proxy: {
      "/api": {
        target: "http://192.168.1.225:5005",
        changeOrigin: true,
        // ws: true,
        followRedirects: true,
        // secure: true,
        rewrite: (path) => path.replace(/^\/api/, ""),
      },
    },
  },
});
